package net.pulseproject.router.modules;

import java.util.Collection;
import java.util.Collections;

import javax.sound.midi.ShortMessage;

import net.pulseproject.commons.midi.Receivable;
import net.pulseproject.commons.midi.Transmitable;

public abstract class BiDirectionalModule extends Module implements Transmitable, Receivable {
	
	private final Collection<Receivable> outgoingModules;
	
	public BiDirectionalModule(final String id, final Collection<Receivable> outgoingModules) {
		super(id);
		if(outgoingModules == null) { throw new IllegalArgumentException("outgoingModules == null"); }
		this.outgoingModules = Collections.unmodifiableCollection(outgoingModules);
	}

	@Override
	public final Collection<Receivable> getOutgoingModules() {
		return this.outgoingModules;
	}
	
	protected final void broadcastToOutgoingModules(final ShortMessage message) {
		for (final Receivable receiver : this.getOutgoingModules()) {
			receiver.receive(message, this);
		}
	}
}
